package cn.gwm.flink.streaming.dwm.charge.assist.gps;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName GpsMatchFactory
 * @Description gps匹配的静态工厂, 提供匹配工具类
 * @Author LiangGuang
 * @Date 2023/06/28 16:26
 */
@Slf4j
public class GpsMatchFactory {

    public static String redis = "redis";
    public static String cache = "cache";
    public static String trip = "trip";
    public static String hbase = "hbase";
    public static String full = "full";
    public static String deep2 = "deep2";


    private static Map<String, GpsMatch> gpsMatchMap = new HashMap<>();

    static {
        CacheGpsMatch cacheGpsMatch = new CacheGpsMatch();
        RedisGpsMatch redisGpsMatch = new RedisGpsMatch();
        TripGpsMatch tripGpsMatch = new TripGpsMatch();
        HbaseGpsMatch hbaseGpsMatch = new HbaseGpsMatch();
        gpsMatchMap.put(cache, cacheGpsMatch);
        gpsMatchMap.put(redis, redisGpsMatch);
        gpsMatchMap.put(trip, tripGpsMatch);
        gpsMatchMap.put(hbase, hbaseGpsMatch);
        // 查询顺序是 cache-redis-trip-hbase
        gpsMatchMap.put(full, hbaseGpsMatch.setNext(hbaseGpsMatch.setNext(redisGpsMatch.setNext(cacheGpsMatch))));
        // 2级深度
        gpsMatchMap.put(deep2, redisGpsMatch.setNext(cacheGpsMatch));

    }

    /**
     * 获取 gps的匹配,默认是 deep2 [cache,redis]
     *
     * @param key
     * @return
     */
    public static GpsMatch getGpsMatch(String key) {
        if (gpsMatchMap.containsKey(key)) {
            return gpsMatchMap.get(key);
        }
        log.error("gps match no {},pleace check!", key);
        return gpsMatchMap.get(deep2);
    }


}
